﻿<script>
    function goBack() {
	window.location.href = "?modul=services&action=services_list";
    }
</script>
<?php

function V_Add_Services($arrayData, $mode) {

    include("../fckeditor/fckeditor.php");
    $ulr = "?" . MODUL . "=services&" . ACTION . "=" . $mode;
    if ($mode == 'Edit_services') {
	$strLable = "Cập nhật dịch vụ";
	$strButton = "Cập nhật";
    } else if ($mode == 'add_services') {
	$strLable = "Thêm mới dịch vụ";
	$strButton = "Thêm mới";
    }
    ?>
    <h3><?= $strLable ?></h3>
    <form enctype="multipart/form-data" action="<?= $ulr ?>" method="post" name="frm" onSubmit="return validateForm();">
        <input type="hidden" name="id" id="id" value="<?= $arrayData['id']; ?>"/>
        <table width="950px" cellpadding="5" border="1">
    	<tr style="background-color: #99CCFF">
    	    <th colspan="2">Thông tin dịch vụ</th>
    	</tr>
    	<tr>
    	    <td width="200px"><strong>Chọn loại dịch vụ</strong></td>
    	    <td>
    		<select name="services_type">
    		    <option value="0">---ROOT---</option>
			<? services_type(0, 0, $arrayData['services_type']); ?>
    		</select>
    	    </td>
    	</tr>
    	<tr>
    	    <td><strong>Tên dịch vụ</strong></td>
    	    <td>
    		<input type="text" name="services_name" id="services_name" value="<?= $arrayData['services_name']; ?>"/>
    	    </td>
    	</tr>
        	<tr>
    	    <td><strong>Ghi chú</strong></td>
    	    <td>
    		<!--    <textarea style="width: 400px; height: 150px" name="services_info" id="services_info"><?= $arrayData['services_info']; ?></textarea> -->
<?php
		    // Lay ve duong dan chinh cua server.
		    $sBasePath = $_SERVER['PHP_SELF'];

		    // Lay ve thu muc goc cho den _sample.
		    $sBasePath = substr($sBasePath, 0, strpos($sBasePath, "run"));
		    //echo "sBasePath = $sBasePath";
		    $sBasePath = $sBasePath . "fckeditor/";
		    $oFCKeditor = new FCKeditor('services_info');
		    $oFCKeditor->BasePath = $sBasePath;
		    $oFCKeditor->Width = '100%';
		    $oFCKeditor->Height = '400';
		    $oFCKeditor->Value = $arrayData["services_info"];
		    $oFCKeditor->Create();
		    ?>
    	    </td>
    	</tr>
    	<tr>
    	    <td colspan="2">
    		<div style="float: right">
    		    <input type="reset" name="reset"  value="Nhập lại"/>
    		    <input type="submit" name="Submit" value="<?= $strButton ?>"/>
    		    <input type="button" name="Back" value="Quay lại" onclick="goBack();"/>
    		</div>
    	    </td>
    	</tr>
        </table>
    </form>
    <?
}

function services_type($parent_id, $level, $id_nhom) {
    global $db;
    $objServices = new MD_Services($db);
    $where = "parent_id = '$parent_id'";
    $order = "";
    $limit = "";
    $array = $objServices->get_services_type_by_Where($where, $order, $limit);
    foreach ($array as $value) {
	$id = $value['id'];
	$selected = "";
	if ($id_nhom == $id) {
	    $selected = "Selected";
	}
	echo '<option ' . $selected . ' value="' . $id . '">' . str_repeat('- - ', $level) . $value['service_type_name'] . '</option>';
	services_type($id, $level + 1, $id_nhom);
    }
}
?>
